Skip to content

ref(android): Narrow consumer keep rules to what the SDK reads - #6779

Open
runningcode wants to merge 4 commits into
mainfrom
no/narrow-android-keep-rules
Open

runningcode wants to merge 4 commits into
mainfrom
no/narrow-android-keep-rules

Conversation

@runningcode

@runningcode runningcode commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

📜 Description

Narrows Android consumer keep rules to the names and members the SDK actually reads by reflection, and drops the app-wide -keepnames class * implements io.sentry.Integration.

💡 Motivation and Context

Google Play adds DEX optimization thresholds in Feb 2027, and library consumer rules count against the app. Part of #6771 (JAVA-856).

  • Replay: isMaskable() now leaves VectorPainter, ColorPainter, and BrushPainter unmasked by type instead of by class name, so no Painter needs to keep its name. Before, an app's own Painter with Vector, Color, or Brush in its name stayed unmasked; it's now masked in debug and release alike.
  • Left as-is on purpose: the enum and SentryOptions rules (hybrid SDKs depend on them), the Throwable rule, -keeppackagenames, and the exception keepnames.

💚 How did you test it?

Built the minified sentry-samples-android release with and without these changes (together with #6778) and ran the same journey on an API 36 emulator: exceptions with screenshot and view hierarchy, Timber, native capture, fragment and Compose testTag click breadcrumbs, Session Replay, and a Java crash on relaunch. Captured the envelopes locally. The events, attachments, view hierarchy tags, breadcrumbs, sdk.integrations, and the integration init logs were identical, and logcat showed no reflection failures.

R8 Configuration Analyzer on the sample: Sentry's rules keep 1,556 items instead of 1,700, and the uncompressed DEX shrinks by 6.5 KB.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

Conflicts with #6778 in sentry-android-core/proguard-rules.pro and CHANGELOG.md. Whichever lands second takes both sides.

🤖 Generated with Claude Code

runningcode and others added 2 commits November 25, 2026 16:19
Classes that are only checked by name now keep just their name, the
NDK entry points keep only init() and close(), replay keeps the names
of the three Painters isMaskable() leaves unmasked, LayoutNode keeps
only the reflected members, and the Compose tag elements keep only
their tag field. The app-wide Integration keepnames is dropped, since
integration names are string literals now.

Refs #6771
Refs JAVA-856

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit 0299f5c.

Main concerns: reach, public contract, data sent to Sentry.

Rules that block low also fired:

  • R6: build or release configuration changed: sentry-android-core/proguard-rules.pro, sentry-android-fragment/proguard-rules.pro, sentry-android-ndk-outproc/proguard-rules.pro, sentry-android-ndk/proguard-rules.pro, sentry-android-replay/proguard-rules.pro and 2 more

This label is a hint for reviewers, not an approval.

@sentry

sentry Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.66.0 (1) release

⚙️ sentry-android Build Distribution Settings

@runningcode
runningcode marked this pull request as ready for review November 26, 2026 07:18
@runningcode
runningcode requested review from a team and adinauer as code owners November 26, 2026 07:18
@runningcode
runningcode requested review from markushi and romtsn and removed request for a team November 26, 2026 07:18
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 26, 2026

@0xadam-brown 0xadam-brown left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One quick comment; otherwise lgtm 👍

# Rules to detect Images/Icons and mask them
-dontwarn androidx.compose.ui.graphics.painter.Painter
-keepnames class * extends androidx.compose.ui.graphics.painter.Painter
# isMaskable() leaves these Painters unmasked by name and masks every other one

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the impl of isMaskable() exempts any painter whose class name contains Color, Vector, or Brush. With the three new keep rules, an app-defined painter with, eg, Color in its name can be unmasked in debug and masked in release after R8 renames it.

Thoughts about keeping the original -keepnames class * extends androidx.compose.ui.graphics.painter.Painter rule to preserve current behavior?

Alternatively, if we only want to exempt these three AndroidX painters, we could check for their types directly in isMaskable() + drop the painter-name rules.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch. I went with checking their types in d242084 let me know if that is what you were thinking!

isMaskable() left any Painter unmasked whose class name contained Vector, Color, or Brush. Once R8 renames an app's painter, that check gave different results in debug and release. Checking the three AndroidX types directly behaves the same in both, and drops their keep rules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 26, 2026
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants